<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>trustedresourceurl.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_html_trustedresourceurl.js.html">trustedresourceurl.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2013 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview The TrustedResourceUrl type and its builders.
<a name="line17"></a> *
<a name="line18"></a> * TODO(user): Link to document stating type contract.
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.html.TrustedResourceUrl&#39;);
<a name="line22"></a>
<a name="line23"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line24"></a>goog.require(&#39;goog.i18n.bidi.Dir&#39;);
<a name="line25"></a>goog.require(&#39;goog.i18n.bidi.DirectionalString&#39;);
<a name="line26"></a>goog.require(&#39;goog.string.Const&#39;);
<a name="line27"></a>goog.require(&#39;goog.string.TypedString&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>
<a name="line31"></a>/**
<a name="line32"></a> * A URL which is under application control and from which script, CSS, and
<a name="line33"></a> * other resources that represent executable code, can be fetched.
<a name="line34"></a> *
<a name="line35"></a> * Given that the URL can only be constructed from strings under application
<a name="line36"></a> * control and is used to load resources, bugs resulting in a malformed URL
<a name="line37"></a> * should not have a security impact and are likely to be easily detectable
<a name="line38"></a> * during testing. Given the wide number of non-RFC compliant URLs in use,
<a name="line39"></a> * stricter validation could prevent some applications from being able to use
<a name="line40"></a> * this type.
<a name="line41"></a> *
<a name="line42"></a> * Instances of this type must be created via the factory method,
<a name="line43"></a> * ({@code goog.html.TrustedResourceUrl.fromConstant}), and not by invoking its
<a name="line44"></a> * constructor. The constructor intentionally takes no parameters and the type
<a name="line45"></a> * is immutable; hence only a default instance corresponding to the empty
<a name="line46"></a> * string can be obtained via constructor invocation.
<a name="line47"></a> *
<a name="line48"></a> * @see goog.html.TrustedResourceUrl#fromConstant
<a name="line49"></a> * @constructor
<a name="line50"></a> * @final
<a name="line51"></a> * @struct
<a name="line52"></a> * @implements {goog.i18n.bidi.DirectionalString}
<a name="line53"></a> * @implements {goog.string.TypedString}
<a name="line54"></a> */
<a name="line55"></a>goog.html.TrustedResourceUrl = function() {
<a name="line56"></a>  /**
<a name="line57"></a>   * The contained value of this TrustedResourceUrl.  The field has a purposely
<a name="line58"></a>   * ugly name to make (non-compiled) code that attempts to directly access this
<a name="line59"></a>   * field stand out.
<a name="line60"></a>   * @private {string}
<a name="line61"></a>   */
<a name="line62"></a>  this.privateDoNotAccessOrElseTrustedResourceUrlWrappedValue_ = &#39;&#39;;
<a name="line63"></a>
<a name="line64"></a>  /**
<a name="line65"></a>   * A type marker used to implement additional run-time type checking.
<a name="line66"></a>   * @see goog.html.TrustedResourceUrl#unwrap
<a name="line67"></a>   * @const
<a name="line68"></a>   * @private
<a name="line69"></a>   */
<a name="line70"></a>  this.TRUSTED_RESOURCE_URL_TYPE_MARKER_GOOG_HTML_SECURITY_PRIVATE_ =
<a name="line71"></a>      goog.html.TrustedResourceUrl.TYPE_MARKER_GOOG_HTML_SECURITY_PRIVATE_;
<a name="line72"></a>};
<a name="line73"></a>
<a name="line74"></a>
<a name="line75"></a>/**
<a name="line76"></a> * @override
<a name="line77"></a> * @const
<a name="line78"></a> */
<a name="line79"></a>goog.html.TrustedResourceUrl.prototype.implementsGoogStringTypedString = true;
<a name="line80"></a>
<a name="line81"></a>
<a name="line82"></a>/**
<a name="line83"></a> * Returns this TrustedResourceUrl&#39;s value as a string.
<a name="line84"></a> *
<a name="line85"></a> * IMPORTANT: In code where it is security relevant that an object&#39;s type is
<a name="line86"></a> * indeed {@code TrustedResourceUrl}, use
<a name="line87"></a> * {@code goog.html.TrustedResourceUrl.unwrap} instead of this method. If in
<a name="line88"></a> * doubt, assume that it&#39;s security relevant. In particular, note that
<a name="line89"></a> * goog.html functions which return a goog.html type do not guarantee that
<a name="line90"></a> * the returned instance is of the right type. For example:
<a name="line91"></a> *
<a name="line92"></a> * &lt;pre&gt;
<a name="line93"></a> * var fakeSafeHtml = new String(&#39;fake&#39;);
<a name="line94"></a> * fakeSafeHtml.__proto__ = goog.html.SafeHtml.prototype;
<a name="line95"></a> * var newSafeHtml = goog.html.SafeHtml.from(fakeSafeHtml);
<a name="line96"></a> * // newSafeHtml is just an alias for fakeSafeHtml, it&#39;s passed through by
<a name="line97"></a> * // goog.html.SafeHtml.from() as fakeSafeHtml instanceof goog.html.SafeHtml.
<a name="line98"></a> * &lt;/pre&gt;
<a name="line99"></a> *
<a name="line100"></a> * @see goog.html.TrustedResourceUrl#unwrap
<a name="line101"></a> * @override
<a name="line102"></a> */
<a name="line103"></a>goog.html.TrustedResourceUrl.prototype.getTypedStringValue = function() {
<a name="line104"></a>  return this.privateDoNotAccessOrElseTrustedResourceUrlWrappedValue_;
<a name="line105"></a>};
<a name="line106"></a>
<a name="line107"></a>
<a name="line108"></a>/**
<a name="line109"></a> * @override
<a name="line110"></a> * @const
<a name="line111"></a> */
<a name="line112"></a>goog.html.TrustedResourceUrl.prototype.implementsGoogI18nBidiDirectionalString =
<a name="line113"></a>    true;
<a name="line114"></a>
<a name="line115"></a>
<a name="line116"></a>/**
<a name="line117"></a> * Returns this URLs directionality, which is always {@code LTR}.
<a name="line118"></a> * @override
<a name="line119"></a> */
<a name="line120"></a>goog.html.TrustedResourceUrl.prototype.getDirection = function() {
<a name="line121"></a>  return goog.i18n.bidi.Dir.LTR;
<a name="line122"></a>};
<a name="line123"></a>
<a name="line124"></a>
<a name="line125"></a>if (goog.DEBUG) {
<a name="line126"></a>  /**
<a name="line127"></a>   * Returns a debug string-representation of this value.
<a name="line128"></a>   *
<a name="line129"></a>   * To obtain the actual string value wrapped in a TrustedResourceUrl, use
<a name="line130"></a>   * {@code goog.html.TrustedResourceUrl.unwrap}.
<a name="line131"></a>   *
<a name="line132"></a>   * @see goog.html.TrustedResourceUrl#unwrap
<a name="line133"></a>   * @override
<a name="line134"></a>   */
<a name="line135"></a>  goog.html.TrustedResourceUrl.prototype.toString = function() {
<a name="line136"></a>    return &#39;TrustedResourceUrl{&#39; +
<a name="line137"></a>        this.privateDoNotAccessOrElseTrustedResourceUrlWrappedValue_ + &#39;}&#39;;
<a name="line138"></a>  };
<a name="line139"></a>}
<a name="line140"></a>
<a name="line141"></a>
<a name="line142"></a>/**
<a name="line143"></a> * Performs a runtime check that the provided object is indeed a
<a name="line144"></a> * TrustedResourceUrl object, and returns its value.
<a name="line145"></a> *
<a name="line146"></a> * @param {!goog.html.TrustedResourceUrl} trustedResourceUrl The object to
<a name="line147"></a> *     extract from.
<a name="line148"></a> * @return {string} The trustedResourceUrl object&#39;s contained string, unless
<a name="line149"></a> *     the run-time type check fails. In that case, {@code unwrap} returns an
<a name="line150"></a> *     innocuous string, or, if assertions are enabled, throws
<a name="line151"></a> *     {@code goog.asserts.AssertionError}.
<a name="line152"></a> */
<a name="line153"></a>goog.html.TrustedResourceUrl.unwrap = function(trustedResourceUrl) {
<a name="line154"></a>  // Perform additional Run-time type-checking to ensure that
<a name="line155"></a>  // trustedResourceUrl is indeed an instance of the expected type.  This
<a name="line156"></a>  // provides some additional protection against security bugs due to
<a name="line157"></a>  // application code that disables type checks.
<a name="line158"></a>  // Specifically, the following checks are performed:
<a name="line159"></a>  // 1. The object is an instance of the expected type.
<a name="line160"></a>  // 2. The object is not an instance of a subclass.
<a name="line161"></a>  // 3. The object carries a type marker for the expected type. &quot;Faking&quot; an
<a name="line162"></a>  // object requires a reference to the type marker, which has names intended
<a name="line163"></a>  // to stand out in code reviews.
<a name="line164"></a>  if (trustedResourceUrl instanceof goog.html.TrustedResourceUrl &amp;&amp;
<a name="line165"></a>      trustedResourceUrl.constructor === goog.html.TrustedResourceUrl &amp;&amp;
<a name="line166"></a>      trustedResourceUrl
<a name="line167"></a>          .TRUSTED_RESOURCE_URL_TYPE_MARKER_GOOG_HTML_SECURITY_PRIVATE_ ===
<a name="line168"></a>              goog.html.TrustedResourceUrl
<a name="line169"></a>                  .TYPE_MARKER_GOOG_HTML_SECURITY_PRIVATE_) {
<a name="line170"></a>    return trustedResourceUrl
<a name="line171"></a>        .privateDoNotAccessOrElseTrustedResourceUrlWrappedValue_;
<a name="line172"></a>  } else {
<a name="line173"></a>    goog.asserts.fail(&#39;expected object of type TrustedResourceUrl, got \&#39;&#39; +
<a name="line174"></a>                      trustedResourceUrl + &#39;\&#39;&#39;);
<a name="line175"></a>    return &#39;type_error:TrustedResourceUrl&#39;;
<a name="line176"></a>
<a name="line177"></a>  }
<a name="line178"></a>};
<a name="line179"></a>
<a name="line180"></a>
<a name="line181"></a>/**
<a name="line182"></a> * Creates a TrustedResourceUrl object from a compile-time constant string.
<a name="line183"></a> *
<a name="line184"></a> * Compile-time constant strings are inherently program-controlled and hence
<a name="line185"></a> * trusted.
<a name="line186"></a> *
<a name="line187"></a> * @param {!goog.string.Const} url A compile-time-constant string from which to
<a name="line188"></a> *     create a TrustedResourceUrl.
<a name="line189"></a> * @return {!goog.html.TrustedResourceUrl} A TrustedResourceUrl object
<a name="line190"></a> *     initialized to {@code url}.
<a name="line191"></a> */
<a name="line192"></a>goog.html.TrustedResourceUrl.fromConstant = function(url) {
<a name="line193"></a>  return goog.html.TrustedResourceUrl
<a name="line194"></a>      .createTrustedResourceUrlSecurityPrivateDoNotAccessOrElse_(
<a name="line195"></a>          goog.string.Const.unwrap(url));
<a name="line196"></a>};
<a name="line197"></a>
<a name="line198"></a>
<a name="line199"></a>/**
<a name="line200"></a> * Type marker for the TrustedResourceUrl type, used to implement additional
<a name="line201"></a> * run-time type checking.
<a name="line202"></a> * @const
<a name="line203"></a> * @private
<a name="line204"></a> */
<a name="line205"></a>goog.html.TrustedResourceUrl.TYPE_MARKER_GOOG_HTML_SECURITY_PRIVATE_ = {};
<a name="line206"></a>
<a name="line207"></a>
<a name="line208"></a>/**
<a name="line209"></a> * Utility method to create TrustedResourceUrl instances.
<a name="line210"></a> *
<a name="line211"></a> * This function is considered &quot;package private&quot;, i.e. calls (using &quot;suppress
<a name="line212"></a> * visibility&quot;) from other files within this package are considered acceptable.
<a name="line213"></a> * DO NOT call this function from outside the goog.html package; use appropriate
<a name="line214"></a> * wrappers instead.
<a name="line215"></a> *
<a name="line216"></a> * @param {string} url The string to initialize the TrustedResourceUrl object
<a name="line217"></a> *     with.
<a name="line218"></a> * @return {!goog.html.TrustedResourceUrl} The initialized TrustedResourceUrl
<a name="line219"></a> *     object.
<a name="line220"></a> * @private
<a name="line221"></a> */
<a name="line222"></a>goog.html.TrustedResourceUrl.
<a name="line223"></a>    createTrustedResourceUrlSecurityPrivateDoNotAccessOrElse_ = function(url) {
<a name="line224"></a>  var trustedResourceUrl = new goog.html.TrustedResourceUrl();
<a name="line225"></a>  trustedResourceUrl.privateDoNotAccessOrElseTrustedResourceUrlWrappedValue_ =
<a name="line226"></a>      url;
<a name="line227"></a>  return trustedResourceUrl;
<a name="line228"></a>};
</pre>


</body>
</html>
